package com.wt.admin.config;

import com.wt.admin.entity.WqunAccount;
import com.wt.admin.entity.rewentity.LoginUser;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class SecUtils {
    public static WqunAccount getUserMess(){
        //获取SecurityContextHolder中的用户信息
        UsernamePasswordAuthenticationToken authenticationToken = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authenticationToken.getPrincipal();
        return loginUser.getWqunAccount();
    }


    //密码加密
//    private static BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
//    public static String encodePassword(String password){
//        return bCryptPasswordEncoder.encode(password);
//    }
//    public static void main(String[] args) {
//        String password = "test";
//        String pwd = encodePassword(password);
//        System.out.println(pwd);
//    }
    public static String passBcrypt(String pass) {
        return new BCryptPasswordEncoder().encode(pass);
    }
}
